<template>
    <div>
        <div>
            <div>
                <el-button type="primary" @click="addBtn" size="mini">添加</el-button>
				<el-button  @click="saveBtn" size="mini" :loading="loading_btn">保存</el-button>
            </div>
        </div>
        <br>
		
        <el-table stripe :data="list"
			ref="multipleTable"
			border  
			style="width: 1200px"
			@selection-change="handleSelectionChange"
			@cell-click="cellClick"
			>
			<el-table-column
			      type="selection"
			      width="55">
			    </el-table-column>
				<!-- <el-table-column  align="center" width="100"  prop="id" label="ID" /> -->
            <el-table-column   align="center"  
				label="账户名称">
				<template slot-scope="scope">
				   <div>
						<el-input  size="mini" v-model="scope.row.account_title"></el-input>
				   </div>
				</template>
			</el-table-column>
            <el-table-column  align="center" label="银行账号">
				<template slot-scope="scope">
				   <div>
						<el-input  size="mini" v-model="scope.row.account_bank"></el-input>
				   </div>
				</template>
			</el-table-column>
             <el-table-column  align="center"   label="账户类型">
             	<template slot-scope="scope">
             	   <div>
             			<el-input  size="mini" v-model="scope.row.account_type"></el-input>
             	   </div>
             	</template>
             </el-table-column>
            <el-table-column   align="center" width="100" label="状态">
				<template slot-scope="scope">
				   <div>
						<el-switch
						  v-model="scope.row.status"
						 :inactive-value="'0'"
						 :active-value="'1'"
						 >
						</el-switch>
				   </div>
				</template>
			</el-table-column>
			<el-table-column  align="center"   label="备注">
				<template slot-scope="scope">
				   <div>
						<el-input  size="mini" v-model="scope.row.remark"></el-input>
				   </div>
				</template>
			</el-table-column>
		 <el-table-column  label="操作"  fixed="left" width="80" align="center">
                <template slot-scope="scope">
					<i v-if="!scope.row.id"  class="el-icon-delete" style="cursor: pointer;"
					@click.stop="delRow(scope)"></i>
					<span v-else>--</span>
                </template>
            </el-table-column>
        </el-table>
        

    </div>
</template>
<script>
    export default {
        components:{
            
        },

        data(){
            return {
				
            }
        },
        mounted(){
            document.title = '往来单位'
			this.lodeList()
			// var _self = this
			// document.onkeydown = function() {
			//   var key = window.event.keyCode
			//   if (key === 13) {
			// 	_self.addBtn()
			//   }
			// }
        },
        methods:{
            delRow(scope){
				let index = scope.$index
				if(scope.row.id){
					this.$message.error('已保存的数据不能删除')
					// this.$confirm('确定删除该客户', '提示', {
					//   confirmButtonText: '确定',
					//   cancelButtonText: '取消',
					//   type: 'warning'
					// }).then(() => {
					// 	this.$post('/baseInfo/delAccount',{id:scope.row.id},res=>{
					// 		this.list.splice(index,1)
					// 		this.$message.success('删除成功')
					// 	})
					// })
				}else{
					this.list.splice(index,1)
				}
            },
            saveBtn(){
				if(this.selectData.length==0) return this.$message.error('请选择')
				let cid = sessionStorage.getItem('cid')
				for(let item of this.selectData){
					item.cid = cid
				}
				this.loading_btn = true
				this.$post('/baseInfo/addEditAccount',this.selectData,res=>{
					this.$message.success('操作成功')
					this.loading_btn = false
					this.lodeList()
				})
			},
			lodeList(){
				this.$post('/baseInfo/getAccountList',{},res=>{
					this.list = res.data.data
				})
			},
            addBtn(){
                let obj = {
                    id:undefined,
					account_title:'',
					account_bank:"",
					account_type:"",
					status:'',
					remark:"",
                }
                this.list.push(obj)
            },
        }
    }
</script>
